package com.chinawayltd.ews.sample.service.common.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chinawayltd.ews.sample.mapper.TLogMapper;
import com.chinawayltd.ews.sample.mapper.common.CommonMapper;
import com.chinawayltd.ews.sample.model.TLog;
import com.chinawayltd.ews.sample.model.TTemplateEvent;
import com.chinawayltd.ews.sample.model.common.CommonVO;
import com.chinawayltd.ews.sample.model.common.MaterielCommonVO;
import com.chinawayltd.ews.sample.service.common.CommonService;
import com.chinawayltd.ews.sample.web.query.LogGirdQuery;

/**
 * @program: g7ews4java-sample
 * @description:
 * @author: xiazj
 * @create: 2018-04-13 18:45
 **/
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private CommonMapper commonMapper;
    @Autowired
    private TLogMapper tLogMapper;
    
    @Override
    public List<CommonVO> listVehicleData(String vehicleCode, Long vehicleId) {
        return commonMapper.listVehicleData(vehicleCode, vehicleId);
    }

    @Override
    public List<CommonVO> listDriverData(String driverName, Long driverId) {
        return commonMapper.listDriverData(driverName, driverId);
    }

    @Override
    public List<CommonVO> listShiftData(String shiftName, Long shiftId) {
        return commonMapper.listShiftData(shiftName, shiftId);
    }

	@Override
	public List<TLog> getLogDataById(LogGirdQuery queryParam) {
		return commonMapper.getLogDataById(queryParam);
	}

	@Override
	public int addLog(Long dataId, String tableName, int i) {
		TLog log = new TLog();
		log.setDataId(dataId);
		log.setTableName(tableName);
		log.setOperationType(i);
		// 内容
		// 用户
		log.setCreateTime(new Date());
		log.setUpdateTime(new Date());
		return tLogMapper.insertSelective(log);
	}

	@Override
	public List<CommonVO> loadBranchData(String branchName, String branchFromType, Long branchId) {
		return commonMapper.loadBranchData(branchName, branchFromType, branchId);
	}

	@Override
	public List<MaterielCommonVO> listMaterielData(String materielName, Long materielId) {
		 return commonMapper.listMaterielData(materielName, materielId);
	}

	@Override
	public List<TTemplateEvent> loadEventListData(String eventName, Long eventId) {
		return commonMapper.loadEventListData(eventName, eventId);
	}

	@Override
	public List<CommonVO> listDictData(String typeCode, String infoName, String infoValue) {
		return commonMapper.listDictData(typeCode, infoName, infoValue);
	}

	@Override
	public List<TTemplateEvent> loadEventListDataByVid(Long vehicleId, String eventName, Long eventId) throws Exception {
		// 判断id是否为空
    	if(vehicleId == null || vehicleId <= 0){
            throw new RuntimeException("车辆不能为空或者少于等于0！");
        }
		return commonMapper.loadEventListDataByVid(vehicleId, eventName, eventId);
	}

}
